package com.catering.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.catering.entity.CateringCart;
import com.catering.entity.CateringOrder;
import com.catering.entity.vo.CateringOrderVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CateringOrderDao extends BaseMapper<CateringOrder> {

    @Select("select t1.*,t2.person,t2.tel_phone,t2.address,t2.detail,t3.user_name,t3.nick_name from catering_order t1 left join catering_address t2 on t1.address_id = t2.sys_id left join catering_user t3 on t3.user_id=t1.user_id ${ew.customSqlSegment}")
    public IPage<CateringOrderVo> selectPageList(IPage<CateringOrder> page, @Param(Constants.WRAPPER) QueryWrapper<CateringCart> queryWrapper);

    @Select("select count(1) from catering_order t1 left join catering_address t2 on t1.address_id = t2.sys_id ${ew.customSqlSegment}")
    public int selectPageCount(@Param(Constants.WRAPPER) QueryWrapper<CateringOrder> queryWrapper);

    @Select("select t1.*,t2.person,t2.tel_phone,t2.address,t2.detail,t2.longitude,t2.latitude,t3.user_name,t3.nick_name from catering_order t1 left join catering_address t2 on t1.address_id = t2.sys_id left join catering_user t3 on t3.user_id=t1.user_id ${ew.customSqlSegment}")
    public List<CateringOrderVo> selectNoPageList(@Param(Constants.WRAPPER) QueryWrapper<CateringOrder> queryWrapper);

    @Select("select ROUND(SUM(IFNULL(pay_money,0))/100,2) as pay_money from catering_order ${ew.customSqlSegment}")
    public String selectSumPay(@Param(Constants.WRAPPER) QueryWrapper<CateringOrder> queryWrapper);
}
